home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / rexx / secretary.avm < prev    next >
Text File  |  1995-03-09  |  12KB  |  454 lines

  1. /* TITLE: avm:rexx/secretary.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse upper arg servername number
  23.  
  24. secretaryDial:
  25. 'dial' number
  26. action = rc
  27. select
  28.   when action = 0 then nop
  29.   when action = 8 then signal secretaryBusy
  30.   when action = 10 then signal secretaryBusy
  31.   when action = 12 then signal stdabort
  32.   when action = 14 then signal stderror
  33.   when action = 16 then signal stderror
  34.   otherwise signal arexxerror
  35. end
  36.  
  37. address rexx 'alertsysop' 'Outgoing'
  38.  
  39. secretaryMenu:
  40. call aapresentmenu('avm:voices/secretary', '0#*', '3')
  41. action = result
  42. select
  43.   when action = '=0' then signal secretaryMenu
  44.   when action = '=1' then nop
  45.   when action = '=2' then nop
  46.   when action = '=3' then nop
  47.   when action = '=4' then nop
  48.   when action = '=5' then nop
  49.   when action = '=6' then nop
  50.   when action = '=7' then nop
  51.   when action = '=8' then nop
  52.   when action = '=9' then nop
  53.   when action = '=#' then do; return; end
  54.   when action = '=*' then signal stdabort
  55.   when action = 4 then signal stdfax
  56.   when action = 5 then signal stddata
  57.   when action = 8 then signal secretaryBusy
  58.   when action = 10 then signal stdtimedout
  59.   when action = 12 then signal stdabort
  60.   when action = 14 then signal stderror
  61.   when action = 16 then signal stderror
  62.   otherwise signal arexxerror
  63. end
  64. return
  65.  
  66. secretaryBusy:
  67. 'delay' 10
  68. action = rc
  69. select
  70.   when action = 0 then nop
  71.   when action = 12 then signal stdabort
  72.   when action = 14 then signal stderror
  73.   when action = 16 then signal stderror
  74.   otherwise signal arexxerror
  75. end
  76. signal secretaryDial
  77.  
  78. /* TITLE: avm:rexx/simplestdtail.avm */
  79. /* This is the standard tail */
  80. exit
  81.  
  82. exit
  83.  
  84. mailboxDir: procedure
  85.     parse arg mailbox
  86.  
  87.     return 'avm:' || mailbox || '/'
  88.  
  89. logFile: procedure
  90.     parse arg mailbox, magiccookie
  91.  
  92.     return 'avm:' || mailbox || '/logs/' || magiccookie
  93.  
  94. voiceFile: procedure
  95.     parse arg mailbox, magiccookie
  96.  
  97.         if (verify(magiccookie, '/:', 'M') = 0) then
  98.           return 'avm:' || mailbox || '/voices/' || magiccookie
  99.         else
  100.           return magiccookie
  101.  
  102. makeUniqueFile: procedure
  103.     if arg() ~= 0 then do
  104.         rc = "makeUniqueFile: bad args"
  105.         signal error
  106.     end
  107.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  108.  
  109. convertToDate: procedure
  110.     if arg() ~= 1 then do
  111.         rc = "convertToDate: bad args"
  112.         signal error
  113.     end
  114.     parse arg timeInC
  115.  
  116.     actualTime = (timeInC - (2922)*86400) // (86400)
  117.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  118.  
  119.     return actualDate /* returning it in 'internal' format */
  120.  
  121. convertToTime: procedure
  122.     if arg() ~= 1 then do
  123.         rc = "convertToTime: bad args"
  124.         signal error
  125.     end
  126.     parse arg timeInC
  127.     
  128.     actualTime = (timeInC - (2922)*86400) // (86400)
  129.  
  130.     return actualTime
  131.  
  132. cTime: procedure
  133.     /* 2922 = 8*365 + 2 */
  134.     /* 86400 = 24*60*60 */
  135.     return (date('i')+2922)*86400 + time('s')
  136.  
  137. /* this returns a handle that you must use after initializing log. */
  138. initLogEntry: procedure expose log.
  139.     if arg() ~= 0 then do
  140.         rc = "initLogEntry: bad args"
  141.         signal error
  142.     end
  143.     
  144.     drop log.
  145.         log. = ''
  146.  
  147.         acidname = getclip(address() || 'CIDNAME')
  148.         acidnumber = getclip(address() || 'CIDNUMBER')
  149.  
  150.     /* 2922 = 8*365 + 2 */
  151.     /* 86400 = 24*60*60 */
  152.     log.time = (date('i')+2922)*86400 + time('s')
  153.     log.cidname = acidname
  154.     log.cidnumber = acidnumber
  155.  
  156.     return
  157.  
  158. loadLogEntry: procedure expose log.
  159.     if arg() ~= 2 then do
  160.         rc = "loadLogEntry: bad args"
  161.         signal error
  162.     end
  163.     parse arg mailbox, handle
  164.  
  165.         drop log.
  166.         log. = ''
  167.  
  168.     if ~exists(mailboxDir(mailbox)) then do
  169.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  170.         return
  171.     end
  172.  
  173.     opened = open(handle, logFile(mailbox, handle), 'r')
  174.         if opened then do
  175.         call showDebugger('Loading entry' logFile(mailbox, handle))
  176.         do while ~eof(handle)
  177.             line = readln(handle)
  178.             parse upper var line variable '=' value
  179.             log.variable = value
  180.         end
  181.         call close(handle)
  182.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  183.     return
  184.  
  185. /* pass a handle here */
  186. saveLogEntry: procedure expose log.
  187.     if arg() ~= 2 then do
  188.         rc = "saveLogEntry: bad args"
  189.         signal error
  190.     end
  191.     parse arg mailbox, handle
  192.  
  193.     if ~exists(mailboxDir(mailbox)) then do
  194.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  195.         return
  196.     end
  197.  
  198.     opened = open(handle, logFile(mailbox, handle), 'w')
  199.  
  200.     if opened then do
  201.         call showDebugger('Saving entry' logFile(mailbox, handle))
  202.         call writeln(handle, 'TYPE=' || log.type)
  203.         call writeln(handle, 'TIME=' || log.time)
  204.         call writeln(handle, 'LENGTH=' || log.length)
  205.  
  206.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  207.  
  208.         call writeln(handle, 'CIDNAME=' || log.cidname)
  209.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  210.  
  211.         call writeln(handle, 'COMMENT=' || log.comment)
  212.  
  213.         call writeln(handle, 'FILENAME=' || log.filename)
  214.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  215.  
  216.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  217.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  218.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  219.  
  220.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  221.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  222.  
  223.         call close(handle)
  224.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  225.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  226.  
  227.     return
  228.  
  229. /* pass a handle here */
  230. updateLogEntry: procedure expose log.
  231.     if arg() ~= 2 then do
  232.         rc = "updateLogEntry: bad args"
  233.         signal error
  234.     end
  235.     parse arg mailbox, handle
  236.  
  237.     if ~exists(mailboxDir(mailbox)) then do
  238.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  239.         return
  240.     end
  241.  
  242.     if ~exists(logFile(mailbox, handle)) then do
  243.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  244.         return
  245.     end
  246.     opened = open(handle, logFile(mailbox, handle), 'w')
  247.  
  248.     if opened then do
  249.         call showDebugger('Updating entry' logFile(mailbox, handle))
  250.         call writeln(handle, 'TYPE=' || log.type)
  251.         call writeln(handle, 'TIME=' || log.time)
  252.         call writeln(handle, 'LENGTH=' || log.length)
  253.  
  254.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  255.  
  256.         call writeln(handle, 'CIDNAME=' || log.cidname)
  257.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  258.  
  259.         call writeln(handle, 'COMMENT=' || log.comment)
  260.  
  261.         call writeln(handle, 'FILENAME=' || log.filename)
  262.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  263.  
  264.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  265.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  266.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  267.  
  268.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  269.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  270.  
  271.         call close(handle)
  272.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  273.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  274.  
  275.     return
  276.  
  277.  
  278.  
  279. showDebugger: procedure
  280.     if arg() ~= 1 then do
  281.         say "showDebugger: ERROR"
  282.         exit 20
  283.     end
  284.  
  285.     parse arg debuggerInfo
  286.     
  287.     firstLine = sourceline(1)
  288.     parse var firstLine '/*' 'TITLE:' title '*/'
  289.     if showlist('p', 'AVMLOGGER') then
  290.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  291.     else
  292.         say title ':' debuggerInfo
  293.  
  294.     return 
  295.  
  296. /*-----------------------------------------------------------------------*/
  297. /*                         signal processing                             */
  298.  
  299. arexxerror:
  300. error:
  301.     call showDebugger("Error" rc "at line" sigl)
  302.     exit 20
  303.  
  304. break_c:
  305. halt:
  306.     call showDebugger("Halt/Break_C at line" sigl)
  307.     exit 20
  308.  
  309. novalue:
  310.     call showDebugger("No value at line" sigl)
  311.     exit 20
  312.  
  313. syntax:
  314.     call showDebugger("Syntax error" rc "at line" sigl)
  315.     exit 20
  316.  
  317. exit
  318.  
  319. /* this requires logfunctions.avm */
  320.  
  321. loadMailbox: procedure expose mailbox.
  322.     if arg() ~= 1 then do
  323.         rc = "loadMailbox: bad args"
  324.         signal error
  325.     end
  326.  
  327.         mailbox. = ''
  328.     parse arg mailbox
  329.  
  330.     handle = 'mailboxconfig'
  331.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  332.     if opened then do
  333.         do while ~eof(handle)
  334.             line = readln(handle)
  335.             parse upper var line variable '=' value
  336.             mailbox.variable = value
  337.         end
  338.         call close(handle)
  339.     end
  340.     return
  341.  
  342. /* pass a handle here */
  343. saveMailbox: procedure expose mailbox.
  344.     if arg() ~= 1 then do
  345.         rc = "saveMailbox: bad args"
  346.         signal error
  347.     end
  348.     parse arg mailbox
  349.  
  350.     handle = 'mailboxconfig'
  351.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  352.  
  353.     if opened then do
  354.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  355.  
  356.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  357.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  358.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  359.  
  360.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  361.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  362.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  363.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  364.  
  365.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  366.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  367.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  368.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  369.  
  370.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  371.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  372.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  373.  
  374.         call close(handle)
  375.     end
  376.  
  377.     return
  378.  
  379. stdabort:
  380. exit
  381.  
  382. stdbusy:
  383. exit
  384.  
  385. stderror:
  386. exit
  387.  
  388. stdtimedout:
  389. exit
  390.  
  391. stdfaxinstruct:
  392. 'playvoice' 'avm:voices/FaxStarting'
  393. action = rc
  394. select
  395.   when action = 0 then nop
  396.   when action = 1 then do; call checkifabort; end
  397.   when action = 4 then nop
  398.   when action = 5 then nop
  399.   when action = 8 then signal stdbusy
  400.   when action = 12 then signal stdabort
  401.   when action = 14 then nop
  402.   when action = 16 then nop
  403.   otherwise signal arexxerror
  404. end
  405.  
  406. stdfax:
  407. faxscript = getclip(address() || 'FAXSCRIPT')
  408. if faxscript = '' then faxscript = 'handlefax'
  409. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  410. else address rexx faxscript address() 'anonymous'
  411. exit
  412.  
  413. stddatainstruct:
  414. 'playvoice' 'avm:voices/DataStarting'
  415. action = rc
  416. select
  417.   when action = 0 then nop
  418.   when action = 1 then do; call checkifabort; end
  419.   when action = 4 then nop
  420.   when action = 5 then nop
  421.   when action = 8 then signal stdbusy
  422.   when action = 12 then signal stdabort
  423.   when action = 14 then nop
  424.   when action = 16 then nop
  425.   otherwise signal arexxerror
  426. end
  427.  
  428. stddata:
  429. datascript = getclip(address() || 'DATASCRIPT')
  430. if datascript = '' then datascript = 'handledata'
  431. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  432. else address rexx datascript address()
  433. exit
  434.  
  435. checkifabort:
  436. 'readnkeys' '1' '3'
  437. action = rc
  438. if action = 0 then value = result
  439. select
  440.   when action = 0 then do; if value = '*' then signal stdabort; end
  441.   when action = 4 then nop
  442.   when action = 5 then nop
  443.   when action = 8 then signal stdbusy
  444.   when action = 10 then nop
  445.   when action = 12 then signal stdabort
  446.   when action = 14 then signal stderror
  447.   when action = 16 then signal stderror
  448.   otherwise signal arexxerror
  449. end
  450. return
  451.  
  452.  
  453.  
  454.